using MongoDB.Driver;
using Sustainalytics.Entities;
using System.Collections.Generic;
using System.Linq;

namespace Sustainalytics.ScreeningTool.Synchronization.Handlers.Governance
{
    public class GovernanceIssueHandler : IHandlerWithGrouping<GovernanceIssue>
    {
        public ProjectionDefinition<GovernanceIssue> GetProjection(ProjectionDefinitionBuilder<GovernanceIssue> builder) => builder
            .Include("Indicators.Name")
            .Include("Indicators.Number")
            .Include("Indicators.Score");

        public IEnumerable<ExtraElement> GetExtraElements(IEnumerable<GovernanceIssue> entities)
            => entities.SelectMany(x => x.Indicators).Select(x => new ExtraElement($"{x.Number} {x.Name}-Score", x.Score));
    }
}
